﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Ccit.OA.NewsCenter
{
    public partial class news_queryset_list : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack){
                _hidTabId.Value = ( null != Request.QueryString["TABID"]) ? Request.QueryString["TABID"].ToString() : "";
                
                _hidPageSource.Value=(null != Request.QueryString["PageSource"]) ? Request.QueryString["PageSource"].ToString() : "";
                _hidType.Value = (null != Request.QueryString["Type"]) ? Request.QueryString["Type"].ToString() : "0";
            }
            initializePage();
        }
        private void initializePage()
        {
            //WindowBLL winbll = new WindowBLL();
            //string PlateIds = winbll.GetPlateIdByType(_hidType.Value);   //获取类型下的板块ids
            QueryBLL bll=new QueryBLL();
            
            gvFastClauseList.DataSource = bll.GetFastClauseList(_hidType.Value);
            gvFastClauseList.DataBind();
        }

        protected void gvFastClauseList_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
        {
            if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;
            string ClauseId = e.KeyValue.ToString();
            HtmlAnchor aDelete = (HtmlAnchor)gvFastClauseList.FindRowCellTemplateControl(e.VisibleIndex, null, "del");
            HtmlAnchor aEdit = (HtmlAnchor)gvFastClauseList.FindRowCellTemplateControl(e.VisibleIndex, null, "aEdit");
            string ClauseName = gvFastClauseList.GetRowValues(e.VisibleIndex, "ClauseName").ToString();
            string FuncType = gvFastClauseList.GetRowValues(e.VisibleIndex, "FuncType").ToString();
            if (FuncType == _hidPageSource.Value)
            {
                aDelete.Attributes["href"] = "javascript:doRemove('" + ClauseId + "')";
                aEdit.Attributes["href"] = "javascript:doLocation('" + ClauseId + "','" + _hidPageSource.Value + "','" + _hidType.Value + "');";
            }
            else
            {
                aDelete.Disabled = true;
                aEdit.Disabled = true;
            }
            
            aEdit.InnerText = ClauseName;
            
        }
        //删除快速查询条件
        [global::System.Web.Services.WebMethod]
        public static string RemoveFastClause(string ClauseId)
        {
            QueryBLL bll = new QueryBLL();
            List<string> strlist = bll.RemoveFastClause(ClauseId);
            var oResult = new { resSign=strlist[0],resMes=strlist[1] };
            string strResult = JavaScriptConvert.SerializeObject(oResult);
            return strResult;
        }
    }
}
